/***
 * 解密的请求配置
 */
import axios from 'axios'
import { decodeString } from './utils'
import store from '../store'
const instance = axios.create()
instance.defaults.timeout = 20000
instance.interceptors.request.use(
  config => {
    store.commit('index/changeLoadingStatus', true)
    return config
  },
  err => {
    return Promise.reject(err)
  }
)
/**
 * http response 拦截器重新配置，重新设置返回值。
 */
instance.interceptors.response.use(
  response => {
    store.commit('index/changeLoadingStatus', false)
    return decodeString(response.data)
  },
  error => {
    store.commit('index/changeLoadingStatus', false)
    return Promise.reject(error.response)
  })

export default instance
